using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
using Yoozoo.Managers.ResourceManagerV2.Framework.Resource;
using Yoozoo.Managers.ResourceManagerV2.Runtime;

public class DualFilteringBlur
{
	private static int brightnessPropertyId;

	private static Material _mat;
    public static Material mat
    {
        get
        {
            if (_mat == null)
            {
               
                    Debug.LogError("需要先加载材质");
               
               
			}
            return _mat;
        }
    }

    public static void InitBlurMaterial()
    {
        UMTResource.LoadAsset("Assets/ResourcesAssets/Materials/mat_dualFilteringBlur.mat",
            (string assetName, object asset, float duration, object userData) =>
            {
                _mat = (Material)asset; 
                brightnessPropertyId = Shader.PropertyToID("_Brightness");
            }, (string assetName, LoadResourceStatus status, string errorMessage, object userData) =>
            {
                Debug.LogError("加载mat_dualFilteringBlur失败");
            });
    }
    public static void DoBlur(RenderTexture source, RenderTexture destination, int iteration, float brightness)
    {
        if (mat!=null)
        {
            var rt = RenderTexture.GetTemporary(source.width / 2, source.height / 2,0);
            rt.name = "DualFilteringBlur_"+ iteration;
            Graphics.Blit(source, rt, mat, 0);

            if (iteration > 0 && rt.width >= 2 && rt.height >= 2) 
            {
                DoBlur(rt, rt, iteration - 1, 1);
            }

            mat.SetFloat(brightnessPropertyId, brightness);
            Graphics.Blit(rt, destination, mat, 1);
            RenderTexture.ReleaseTemporary(rt);
        }
      
    }

}

